package com.example.crud.fhys.controller;

import com.example.common.core.BaseController;
import com.example.common.core.MybatisPlusUtil;
import com.example.crud.fhys.assembler.ProjectConvert;
import com.example.crud.fhys.po.ProPeople;
import com.example.crud.fhys.po.Project;
import com.example.crud.fhys.service.ProPeopleService;
import com.example.crud.fhys.service.ProjectService;
import com.example.crud.fhys.vo.in.ProjectConditionInVO;
import com.example.crud.fhys.vo.in.ProjectInVO;
import com.example.crud.fhys.vo.out.ProjectOutVO;
import com.github.houbb.data.factory.core.util.DataUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * (Project)表控制层
 *
 * @author zjarlin
 * @since 2023-02-26 16:22:41
 */
@Api(tags = "project")
@RestController
@RequestMapping("/fhys/project")
public class ProjectController extends BaseController<ProjectService, ProjectConvert
    , ProjectConditionInVO
    , ProjectInVO
    , ProjectOutVO
    , Project
    > {
    //@Autowired
    @Autowired
    ProjectService projectService;

    @Autowired
    ProPeopleService proPeopleService;

    @PostMapping("testCascadeInsert")
    @ApiOperation("测试级联插入")
    public void djaoisjdo(@RequestBody Project p) {

        ProPeople b1 = DataUtil.build(ProPeople.class);
        ProPeople b2 = DataUtil.build(ProPeople.class);
        ProPeople b3 = DataUtil.build(ProPeople.class);
        List<ProPeople> bs = Arrays.asList(b1, b2, b3);
        bs.forEach(e -> {
            //e.setDeleted(0);
            e.setRecorder("1");
        });
        Project build1 = DataUtil.build(Project.class);
        build1.setRecheckFlag("1");
        build1.setHasBeenStamped("1");
        //build1.setDeleted(0);
        build1.setProvinceCode("1");
        build1.setCountyCode("1");
        build1.setCityCode("2");

        MybatisPlusUtil<Project, ProPeople> of1 = MybatisPlusUtil.of(projectService, proPeopleService);
        of1.pSave(build1, bs, Project::getId, ProPeople::setProjectId);
    }

    @PostMapping("shanchu")
    @ApiOperation("测试级联shanchu ")
    public void shanchu(@RequestBody Project p) {

        ProPeople b1 = DataUtil.build(ProPeople.class);
        ProPeople b2 = DataUtil.build(ProPeople.class);
        ProPeople b3 = DataUtil.build(ProPeople.class);
        List<ProPeople> cs = Arrays.asList(b1, b2, b3);
        cs.forEach(e -> {
            //e.setDeleted(0);
            e.setRecorder("1");
        });
        Project par = DataUtil.build(Project.class);
        par.setRecheckFlag("1");
        par.setHasBeenStamped("1");
        //par.setDeleted(0);
        par.setProvinceCode("1");
        par.setCountyCode("1");
        par.setCityCode("2");
        par.setId("UsxaI");

        MybatisPlusUtil<Project, ProPeople> of1 = MybatisPlusUtil.of(projectService, proPeopleService);
        boolean b = of1.pRemove(par, Project::getId, ProPeople::getProjectId);
    }

}

